import java.util.Arrays;

/**
 * @ wenbin
 * @ date 2020/4/14
 */
public class Solution6 {
    public int minNumberInRotateArray1(int [] array) {
        if(array.length==0)
            return 0;
        Arrays.sort(array);
        return array[0];
    }

    public static int minNumberInRotateArray(int[] array) {
        if (array.length == 0)
            return 0;
        int left = 0;
        int right = array.length - 1;
        int middle = -1;
        while (array[left] >= array[right]) {
            if (right - left == 1) {
                middle = right;
                break;
            }
            middle = left + (right - left) / 2;
            if (array[middle] >= array[left]) {
                left = middle;
            }
            if (array[middle] <= array[right]) {
                right = middle;
            }
        }
        return array[middle];
    }
    public int minNumberInRotateArray3(int[] array) {
        if (array.length ==0)
            return 0;
        for (int i =0; i < array.length -1; i++) {
            if (array[i] > array[i +1])
                return array[i +1];
        }
        return array[0];
    }

    public static void main(String[] args) {
         int arr[]={3,4,5,1,2};
        Solution6 soultion6 = new Solution6();
        int i=soultion6.minNumberInRotateArray(arr);
    }
}
